package org.x.casemodule.mapper;

import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.x.casemodule.entity.ScheduleEventEntity;
import org.x.casemodule.entity.ScheduleReminderEntity;

import java.util.Date;
import java.util.List;




@Mapper
public interface ScheduleEventMapper extends BaseMapper<ScheduleEventEntity> {




    @Select("SELECT * FROM schedule_event " +
            "WHERE creator_id = #{creatorId} " +
            "AND status = 'ACTIVE' " +
            "AND (start_time < #{endTime} AND end_time > #{startTime})")
    List<ScheduleEventEntity> findConflictingEvents(@Param("creatorId") Long creatorId,
                                                    @Param("startTime") Date startTime,
                                                    @Param("endTime") Date endTime);



    // ScheduleEventMapper.java
    @Select("SELECT * FROM schedule_event " +
            "WHERE status = 'ACTIVE' " +
            "AND start_time >= #{startTime} " +
            "AND end_time <= #{endTime}")
    List<ScheduleEventEntity> findEventsByTimeRange(@Param("startTime") Date startTime,
                                                    @Param("endTime") Date endTime);

    @Select("SELECT * FROM schedule_reminder WHERE event_id = #{eventId}")
    List<ScheduleReminderEntity> findByEventId(@Param("eventId") Long eventId);



    // 在 ScheduleEventMapper.java 接口中添加新方法
    @Select("SELECT se.* FROM schedule_event se " +
            "JOIN schedule_share ss ON se.id = ss.event_id " +
            "WHERE ss.to_user_id = #{userId} " +
            "AND se.status = 'ACTIVE' " +
            "AND se.start_time >= #{startTime} " +
            "AND se.end_time <= #{endTime}")
    List<ScheduleEventEntity> findSharedEventsByTimeRange(@Param("userId") Long userId,
                                                          @Param("startTime") Date startTime,
                                                          @Param("endTime") Date endTime);





}




